package com.ssyt.hiringtwo.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.ssyt.hiringtwo.entity.UserEntity;


/**
 * 所有的Action继承此类
 *
 */
public class BaseAction {

    /**
     * 获取Session
     * 
     * @return
     */
    public HttpSession getSession() {
        return ServletActionContext.getRequest().getSession();
    }

    /**
     * 从Session中获取求职者信息
     */
    public UserEntity getTalent() {
        UserEntity userEntity = (UserEntity) getSession().getAttribute("userEntity");
        return userEntity;
    }

    /**
     * 从Session中获取求职者id
     */
    public int getTalentId() {
        return getTalent().getId();
    }
    /**
     * response输出
     * 
     * @throws IOException
     */
    public void responseStr(String str) {
        HttpServletResponse response = ServletActionContext.getResponse();
        response.setCharacterEncoding("UTF-8");

        PrintWriter writer = null;
        try {
            writer = response.getWriter();
            writer.print(str);
        } catch (Exception e) {

        } finally {
            if (writer != null) {
                writer.close();
            }
        }
    }
}
